from flask import Flask, jsonify, request
from flask_cors import CORS
import mysql.connector

app = Flask(__name__)
CORS(app)  # 允许所有域的跨域请求

# 配置MySQL连接
db = mysql.connector.connect(
    host="localhost",
    user="develop",
    password="P7rT#u9@yN2",
    database="ads"
)

@app.route('/api/daily_report', methods=['GET'])
def get_daily_report():
    replay_date = request.args.get('replay_date')
    if not replay_date:
        return jsonify({'error': 'replay_date parameter is missing'}), 400

    cursor = db.cursor(dictionary=True)
    query = """
    SELECT * FROM ads_daily_report_i_d
    WHERE replay_date = %s
    """
    cursor.execute(query, (replay_date,))
    results = cursor.fetchall()
    cursor.close()

    return jsonify(results)

if __name__ == '__main__':
    app.run(host='0.0.0.0',debug=True, port=5011)
